package com.crosspaste.exception

val standardErrorCodeMap: Map<Int, ErrorCodeSupplier> =
    StandardErrorCode.entries.associateBy { it.getCode() }

enum class StandardErrorCode(
    code: Int,
    errorType: ErrorType,
) : ErrorCodeSupplier {
    UNKNOWN_ERROR(0, ErrorType.INTERNAL_ERROR),
    BOOTSTRAP_ERROR(1, ErrorType.INTERNAL_ERROR),
    INVALID_PARAMETER(2, ErrorType.USER_ERROR),
    NOT_FOUND_API(3, ErrorType.USER_ERROR),

    CANT_CREATE_DIR(100, ErrorType.INTERNAL_ERROR),
    CANT_CREATE_FILE(101, ErrorType.INTERNAL_ERROR),
    OUT_RANGE_CHUNK_INDEX(102, ErrorType.INTERNAL_ERROR),

    NOT_FOUND_APP_INSTANCE_ID(1000, ErrorType.EXTERNAL_ERROR),
    TOKEN_INVALID(1001, ErrorType.EXTERNAL_ERROR),
    NOT_FOUND_SOURCE(1002, ErrorType.EXTERNAL_ERROR),
    NOT_FOUND_ICON(1003, ErrorType.EXTERNAL_ERROR),
    CLEAN_PASTE_TASK_FAIL(1004, ErrorType.EXTERNAL_ERROR),
    DELETE_TASK_FAIL(1005, ErrorType.EXTERNAL_ERROR),
    HTML_2_IMAGE_TASK_FAIL(1006, ErrorType.EXTERNAL_ERROR),
    PULL_FILE_TASK_FAIL(1007, ErrorType.EXTERNAL_ERROR),
    PULL_FILE_CHUNK_TASK_FAIL(1008, ErrorType.EXTERNAL_ERROR),
    PULL_ICON_TASK_FAIL(1009, ErrorType.EXTERNAL_ERROR),
    NOT_FOUND_FILES_INDEX(1010, ErrorType.EXTERNAL_ERROR),
    NOT_MATCH_APP_INSTANCE_ID(1011, ErrorType.EXTERNAL_ERROR),
    CLEAN_TASK_FAIL(1012, ErrorType.EXTERNAL_ERROR),
    SWITCH_LANGUAGE_TASK_FAIL(1013, ErrorType.EXTERNAL_ERROR),
    OPEN_GRAPH_TASK_FAIL(1014, ErrorType.EXTERNAL_ERROR),

    SIGN_INVALID(2000, ErrorType.EXTERNAL_ERROR),
    EXCHANGE_FAIL(2001, ErrorType.EXTERNAL_ERROR),
    EXCHANGE_TIMEOUT(2002, ErrorType.EXTERNAL_ERROR),
    UNTRUSTED_IDENTITY(2003, ErrorType.EXTERNAL_ERROR),
    TRUST_FAIL(2005, ErrorType.EXTERNAL_ERROR),
    TRUST_TIMEOUT(2006, ErrorType.EXTERNAL_ERROR),
    ENCRYPT_FAIL(2007, ErrorType.INTERNAL_ERROR),
    DECRYPT_FAIL(2008, ErrorType.EXTERNAL_ERROR),

    SYNC_PASTE_ERROR(3000, ErrorType.EXTERNAL_ERROR),
    SYNC_PASTE_NOT_FOUND_RESOURCE(3001, ErrorType.EXTERNAL_ERROR),
    SYNC_PASTE_NOT_FOUND_DATA(3002, ErrorType.EXTERNAL_ERROR),

    SYNC_NOT_ALLOW_RECEIVE_BY_USER(4000, ErrorType.USER_ERROR),
    SYNC_NOT_ALLOW_SEND_BY_USER(4001, ErrorType.USER_ERROR),
    CANT_GET_SYNC_ADDRESS(4002, ErrorType.USER_ERROR),
    SYNC_NOT_ALLOW_RECEIVE_BY_APP(4003, ErrorType.INTERNAL_ERROR),
    SYNC_NOT_ALLOW_SEND_BY_APP(4004, ErrorType.INTERNAL_ERROR),

    EXPORT_FAIL(5000, ErrorType.INTERNAL_ERROR),
    IMPORT_FAIL(5001, ErrorType.INTERNAL_ERROR),
    ;

    private val errorCode: ErrorCode = ErrorCode(code, name, errorType)

    override fun toErrorCode(): ErrorCode = errorCode

    fun getCode(): Int = errorCode.code
}
